/* js for TP2/jeu, by XIAO Yang & MEHAS Mehdi. */

var randomNO=-1;
var count=0;
function generateNo(){
	randomNO=Math.floor(Math.random()*1001);
}

function displaySolution(){
	if(randomNO==-1)
		document.jeu.display.value+="We didn't start the game!\nPlease click [Nouvelle Partie] to start it!\n";
	else
		document.jeu.display.value+="\nThe number is: "+randomNO+"\n";
}

function confirmStart(){
	if(confirm('Commencer une nouvelle partie ?'))
		{
			count=0;
			generateNo();
			document.jeu.display.value="";
			document.jeu.nbinput.value="";
			document.jeu.nbinput.focus();
		}
	else
		document.jeu.display.value+="Please click the button [Nouvelle Partie] to start the game!\n";
}

function check(){
	if(document.jeu.nbinput.value<=1000 & document.jeu.nbinput.value>=0 & randomNO!=-1){
		var no=document.jeu.nbinput.value;
		count++;
		if(no<randomNO){
			document.jeu.display.value+="My number is greater than "+no+".\n";
			document.jeu.nbinput.value="";
			document.jeu.nbinput.focus();
		}
		else if(no>randomNO){
			document.jeu.display.value+="My number is less than "+no+".\n";
			document.jeu.nbinput.value="";
			document.jeu.nbinput.focus();
		}
		else	{
			alert("Congratulation! It takes you "+count+" attempts to get this number");
			document.jeu.display.value+="Congratulation! You are right! The number is "+randomNO+".\nPlease click [Nouvelle Partie] to start a new game!";
		}
	}
	else if(randomNO==-1)
		alert("We didn't start the game!\nPlease click [Nouvelle Partie] to start it!");
	else
		alert("Vous devez sisir un nombre entre 0 et 1000!");
}

